//
//  ModuleWriterViewController.m
//  CocoaSynth
//
//  Created by Thomas Dupont on 22/02/10.
//  Copyright 2010 Apple Inc. All rights reserved.
//

#import "ModuleWriterViewController.h"

#import "ModuleWriterView.h"
#import "ModuleView.h"
#import "PortOutView.h"
#import "PortInView.h"
#import "MixingViewController.h"
#import "PortViewController.h"
#import "PortInViewController.h"
#import "PortOutViewController.h"
#import "PortOutProtocol.h"
#import "Module.h"
#import "ParametersWriter.h"
#import "ParametersModule.h"

#define WRITERWIDTH 74
#define WRITERHEIGHT 71
#define PORTDECALAGE 10

@implementation ModuleWriterViewController

- (id)init
{
	if (self = [super init]) {
		ModuleView* moduleView = [[ModuleWriterView alloc] initWithFrame:NSMakeRect(0, 0, WRITERWIDTH, WRITERHEIGHT)];
		[moduleView setController:self];
		self.view = moduleView;
		
		parameters = [[ParametersWriter alloc] initWithNibName:@"ParametersWriter" bundle:nil];
		[parameters setModule:self];
		
		[moduleView release];
	}
	return self;
}

- (void)setModel:(Module *)aModule
{
	[super setModel:aModule];
	
	NSPoint point;
	
	point.x = 10;
	point.y = WRITERHEIGHT / 2 - PORTDECALAGE;
	PortViewController* portIn = [[PortInViewController alloc] initWithPortIn:[model portIn] atPoint:point];
	[portIn setModule:self];
	[self.view addSubview:portIn.view];
	[portsIn addObject:portIn];
	[portIn release];
}

- (void)displayParameterView
{
	[mixingController displayParameterView:self];
}

- (NSViewController<ParametersModule>*)parameters
{
	return parameters;
}

- (void)highlight
{
	[(ModuleWriterView*)self.view setHighlight:YES];
	[self.view setNeedsDisplay:YES];
}

- (void)unhighlight
{
	[(ModuleWriterView*)self.view setHighlight:NO];
	[self.view setNeedsDisplay:YES];
}

- (void)dealloc
{
	[parameters release];
	[super dealloc];
}

@end
